﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using TrainingWorkshop.IDAL;
using TrainingWorkshop.DAL_EF.Translator;

namespace TrainingWorkshop.DAL_EF
{
    public class StudentRepository_EF:IStudentRepository
    {
        /// <summary>
        /// get students who take given course
        /// </summary>
        /// <param name="CourseId">Given courseId</param>
        /// <returns>list of studnet</returns>
        public List<Model.Student> StudentsTakeCourse(int CourseId)
        {
            List<Student> temp = new List<Student>();
            using (var db = new projectbEntities()) 
            {
                var query = from s in db.Students
                            join cd in db.CourseDetails
                            on s.StudentId equals cd.StudentId
                            where cd.CourseId == CourseId
                            select s;

                temp = query.ToList();
            }
            return StudentTranslator.EFToModelStudent(temp);
        }

        /// <summary>
        /// get students who do no take given course
        /// </summary>
        /// <param name="CourseId">given courseId</param>
        /// <returns>lis of studnet</returns>
        public List<Model.Student> StudentsNotTakeCourse(int CourseId)
        {
            List<Student> temp = new List<Student>();
            using (var db = new projectbEntities()) {

                var queryStudentId = (from s in db.Students
                             select s).Except(
                           from si in db.Students
                           join cd in db.CourseDetails
                           on si.StudentId equals cd.StudentId
                           where cd.CourseId == CourseId
                           select si
                           );
                temp = queryStudentId.ToList();
            }
            return StudentTranslator.EFToModelStudent(temp);
        }
    }
}
